package com.aaa.controller;

import com.aaa.service.F_YuanGongService;
import com.aaa.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("yuangong")
/**
 * 员工管理
 */
public class F_YuanGongControllerF {
@Autowired
F_YuanGongService service;

    /**
     * 查询所有员工
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object List(@RequestBody Map map){
        System.out.println(map);
        List<Map> data = service.selectList(map);
        Integer total = service.getCount(map);
        Map zmap = new HashMap();
        zmap.put("data",data);
        zmap.put("total",total);
        System.out.println(zmap);
        return zmap;
}

    /**
     * 获取roleid
     * @return
     */
  @RequestMapping("/getRole")
    @ResponseBody
    public Object getRole(){
        List<Map> data = service.getRole();
        Map zmap = new HashMap();
        zmap.put("options",data);
        System.out.println("options+++"+zmap);
        return zmap;
    }
    /**
     * 获取roleid
     * @return
     */
    @RequestMapping("/getshi")
    @ResponseBody
    public Object getShi(){
        List<Map> data = service.getShi();
        Map zmap = new HashMap();
        zmap.put("options2",data);
        System.out.println("options2+++"+zmap);
        return zmap;
    }
    /**
     * 员工删除
     * @param id
     * @return
     */
    @RequestMapping("del")
@ResponseBody
public Integer del(Integer id){
    //System.out.println(id);
    int row = service.delEmp(id);
    return row;
}

    /**
     * 多选删除
     * @param ids
     * @return
     */
    @RequestMapping("batchDel")
    @ResponseBody
    public Integer batchDel(Integer... ids){
        //System.out.println(id);
        int row;
        for (int i = 0; i < ids.length; i++) {
            row = service.delEmp(ids[i]);
          }
        return 2;
    }

    /**
     * 添加员工
     * @param map
     * @return
     */
    @RequestMapping("/add")
    @ResponseBody
    public Integer add(@RequestBody Map map){

       String s = (String) map.get("password");
        MD5 md5=new MD5();
        String password=md5.MD5(s);
        //System.out.println(password);
        map.put("password1",password);

      int row=service.add(map);
        return row;
    }

    /**
     * 修改员工
     * @param map
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public Integer update(@RequestBody Map map){
        System.out.println(map+"ssssssss");
        int row=service.update(map);
        return row;
    }


}
